//package com.items.blog.service;
//
//
//import lombok.extern.slf4j.Slf4j;
//import org.apache.ibatis.annotations.Select;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.mail.javamail.JavaMailSender;
//import org.springframework.mail.javamail.MimeMailMessage;
//import org.springframework.mail.javamail.MimeMessageHelper;
//import org.springframework.scheduling.annotation.Async;
//import org.springframework.stereotype.Component;
//import org.springframework.stereotype.Service;
//import org.thymeleaf.TemplateEngine;
//import org.thymeleaf.context.Context;
//import org.thymeleaf.context.IContext;
//
//import javax.annotation.Resource;
//import javax.mail.MessagingException;
//import javax.mail.internet.MimeMessage;
//import java.util.Date;
//
//@Service
//public class MailService {
//
//    @Value("${spring.mail.username}")
//    private String mailUsername;
//
//    @Autowired
//    private JavaMailSender javaMailSender;
//    //模板引擎
//
//    @Resource
//    private TemplateEngine templateEngine;
//
//    //账号激活时发送邮件
//    //activationUrl 激活url链接
//    //email 收件人邮箱
//    @Async
//    public void sendMailForActivationAccount(String activationUrl,String email){
//        //创建邮件对象
//        MimeMessage mimeMessage = javaMailSender.createMimeMessage();
//        try{
//            MimeMessageHelper message = new MimeMessageHelper(mimeMessage,1);
//            //设置邮件主题
//            message.setSubject("个人账号激活");
//            //设置邮件发送者
//            message.setFrom(mailUsername);
//            //设置邮件接收者，可以多个
//            message.setTo(email);
//            //设置邮件抄送人，可以多个
//            //message.setCc();
//            //设置隐秘抄送人，可以多个
//           // message.setBcc();
//            //设置邮件发送日期
//            message.setSentDate(new Date());
//            //创建上下文环境 thymeleaf包
//            Context context =new Context();
//            context.setVariable("activationUrl",activationUrl);
//            String text =templateEngine.process("activation-account.html",context);
//            //设置邮件的正文
//            message.setText(text,true);
//
//        }catch (MessagingException e){
//            e.printStackTrace();
//        }
//            //邮件发送
//        javaMailSender.send(mimeMessage);
//
//
//    }
//}
